/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.storage.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeesite.modules.storage.entity.Route;
import com.jeesite.modules.storage.service.ActivityService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.storage.entity.PlateItem;
import com.jeesite.modules.storage.service.PlateItemService;

/**
 * 模块项Controller
 */
@Controller(value = "webplateitem")
@RequestMapping(value = "${adminPath}/storage/plate/item")
public class PlateItemController extends BaseController {

	@Autowired
	private PlateItemService plateItemService;

	@Autowired
	private ActivityService activityService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public PlateItem get(String id, boolean isNewRecord) {
		return plateItemService.get(id, isNewRecord);
	}

	/**
	 * 查询列表数据
	 */
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<PlateItem> listData(PlateItem plateItem, HttpServletRequest request, HttpServletResponse response) {
		plateItem.setPage(new Page<>(request, response));
		Page<PlateItem> page = plateItemService.findPage(plateItem);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequestMapping(value = "form")
	public String form(PlateItem plateItem, Model model) {
		model.addAttribute("plateItem", plateItem);
		return "modules/storage/plate/item/form";
	}

	/**
	 * 保存模块项
	 */
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated PlateItem plateItem) {
		try{
			plateItemService.save(plateItem);
			return renderResult(Global.TRUE, text("保存模块项成功！"));
		}catch (Exception ex){
			return renderResult(Global.FALSE, text(ex.getMessage()));
		}
	}
	
	/**
	 * 删除模块项
	 */
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(PlateItem plateItem) {
		try{
			plateItemService.delete(plateItem);
			return renderResult(Global.TRUE, text("删除模块项成功！"));
		}catch (Exception ex){
			return renderResult(Global.FALSE, text(ex.getMessage()));
		}
	}
	
}